package com.tcj.myprogram.memorialday.myview;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.tcj.myprogram.memorialday.BaseActivity;
import com.tcj.myprogram.memorialday.R;
import com.tcj.myprogram.voiceschedule.db.DbUnit;

/**
 * Baes My View 所有的MyView都繼承它
 */
abstract public class MyView {

	protected BaseActivity baseActivity;
	protected View view;
	protected boolean showAD = true;
	protected DbUnit dbUnit;
	protected Menu menu;
	// Log使用
	public static String TAG;

	// 將XML轉成UI
	LayoutInflater layoutInflater;

	public boolean isShowAD() {
		return showAD;
	}

	public MyView(BaseActivity baseActivity) {
		this.baseActivity = baseActivity;
		TAG = BaseActivity.TAG_BASE + "-" + getClass().getName();
		dbUnit = DbUnit.getInstance(baseActivity);
		layoutInflater = (LayoutInflater) baseActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	public View getView() {
		return view;
	}

	abstract public void doOnDestroy();

	abstract public void doOnCreate(Bundle savedInstanceState);

	abstract public void doOnStart();

	abstract public void doOnResume();

	abstract public void doOnPause();

	protected void setViewByLayouyId(int layoutId) {
		view = layoutInflater.inflate(layoutId, null);
	}

	public void doOnConfigurationChanged(Configuration newConfig) {
		// do nothing.
	}

	public boolean doOnBackKeyPress() {
		return false;
	}

	public void doHandleMessage(Message msg) {

	}

	public void doSetRequestedOrientation(int requestedOrientation) {

	}

	/**
	 * 預設沒有Menu
	 * 
	 * @return
	 */
	public int getMenuId() {
		// return R.menu.main;
		return -1;
	}

	public void doOnActivityResult(int requestCode, int resultCode, Intent data) {

	}

	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	public String getString(int id) {
		return baseActivity.getString(id);
	}

	public boolean doOnOptionsItemSelected(MenuItem item) {
		return true;
	}

}
